
import java.awt.Graphics;
import java.awt.Point;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * editorGrafico.java
 *
 * Created on 20-may-2011, 18:33:42
 */
/**
 *
 * @author bosco
 */
public class editorGrafico extends java.awt.Frame {

    int valorPintar=0;
    int valorColor=1;
    private listaObjetos nuestrosObjetos = new listaObjetos();

    int xIniTemp = 0;
    int yIniTemp = 0;
    int xFinTemp = 0;
    int yFinTemp = 0;




    /** Creates new form editorGrafico */
    public editorGrafico() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        button1 = new java.awt.Button();
        button2 = new java.awt.Button();
        button3 = new java.awt.Button();
        label1 = new java.awt.Label();
        label2 = new java.awt.Label();
        label3 = new java.awt.Label();
        scrollbar1 = new java.awt.Scrollbar();
        label4 = new java.awt.Label();
        button4 = new java.awt.Button();
        button5 = new java.awt.Button();
        label5 = new java.awt.Label();
        label6 = new java.awt.Label();
        menuBar1 = new java.awt.MenuBar();
        File = new java.awt.Menu();
        menuItem1 = new java.awt.MenuItem();
        menuItem2 = new java.awt.MenuItem();
        menuItem3 = new java.awt.MenuItem();

        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botonPulsado(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                botonSoltado(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });
        setLayout(null);

        button1.setLabel("Lineas");
        button1.setName("bLineas"); // NOI18N
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });
        add(button1);
        button1.setBounds(10, 70, 80, 23);

        button2.setLabel("Circulos");
        button2.setName("bCirculos"); // NOI18N
        button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button2ActionPerformed(evt);
            }
        });
        add(button2);
        button2.setBounds(10, 100, 80, 23);

        button3.setLabel("Rectangulos");
        button3.setName("bRectangulos"); // NOI18N
        button3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button3ActionPerformed(evt);
            }
        });
        add(button3);
        button3.setBounds(10, 130, 80, 23);

        label1.setEnabled(false);
        label1.setName("label1"); // NOI18N
        label1.setText("Estas pintando lineas");
        add(label1);
        label1.setBounds(10, 410, 160, 19);

        label2.setEnabled(false);
        label2.setName("label2"); // NOI18N
        label2.setText("Estas pintando circulos");
        add(label2);
        label2.setBounds(10, 430, 160, 19);

        label3.setEnabled(false);
        label3.setName("label3"); // NOI18N
        label3.setText("Estas pintando rectangulos");
        add(label3);
        label3.setBounds(10, 450, 180, 19);

        scrollbar1.setBlockIncrement(1);
        scrollbar1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        scrollbar1.setName("scroll1"); // NOI18N
        scrollbar1.setOrientation(java.awt.Scrollbar.HORIZONTAL);
        add(scrollbar1);
        scrollbar1.setBounds(10, 220, 130, 16);

        label4.setName("label4"); // NOI18N
        label4.setText("Transparencia");
        add(label4);
        label4.setBounds(10, 200, 100, 19);

        button4.setLabel("Negro");
        button4.setName("button4"); // NOI18N
        button4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button4ActionPerformed(evt);
            }
        });
        add(button4);
        button4.setBounds(10, 310, 60, 23);

        button5.setLabel("Rojo");
        button5.setName("button5"); // NOI18N
        button5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button5ActionPerformed(evt);
            }
        });
        add(button5);
        button5.setBounds(10, 340, 60, 23);

        label5.setName("label5"); // NOI18N
        label5.setText("Color");
        add(label5);
        label5.setBounds(10, 290, 36, 19);

        label6.setEnabled(false);
        label6.setName("label6"); // NOI18N
        label6.setText("(deshabilitado)");
        add(label6);
        label6.setBounds(10, 240, 100, 19);

        File.setLabel("File");

        menuItem1.setLabel("Salvar");
        menuItem1.setName("menu1");
        File.add(menuItem1);

        menuItem2.setLabel("Limpiar");
        menuItem2.setName("menu2");
        File.add(menuItem2);

        menuItem3.setLabel("Nuevo");
        menuItem3.setName("menuitem3");
        menuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem3ActionPerformed(evt);
            }
        });
        File.add(menuItem3);

        menuBar1.add(File);

        setMenuBar(menuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        System.exit(0);
    }//GEN-LAST:event_exitForm

    private void botonPulsado(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonPulsado
        // TODO add your handling code here:
        
        Point punto = evt.getPoint();
        xIniTemp = punto.x;
        yIniTemp = punto.y;
    }//GEN-LAST:event_botonPulsado

    private void botonSoltado(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonSoltado
        // TODO add your handling code here:
     

        Point punto = evt.getPoint();
        xFinTemp = punto.x;
        yFinTemp = punto.y;
        




        objetoLinea nElemento = new objetoLinea(xIniTemp, yIniTemp, xFinTemp, yFinTemp);
        objetoCirculo nElemento2 = new objetoCirculo(xIniTemp, xIniTemp, xFinTemp, yFinTemp);
        objetoRectangulo nElemento3 = new objetoRectangulo(xIniTemp, xIniTemp, xFinTemp, yFinTemp);
        color ncolor =new color(valorColor);

       // ncolor.pinta(null, null);

        Graphics g = this.getGraphics();
        if(valorPintar==1){
            nElemento.pinta(g);
        }
        if(valorPintar==2){
            nElemento2.pinta(g);
        }
        if(valorPintar==3){
            nElemento3.pinta(g);
        }
        g.dispose();

        nuestrosObjetos.insertaElemento(nElemento);
    }//GEN-LAST:event_botonSoltado

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
        // TODO add your handling code here:
        valorPintar=1;
        label1.enable(true);
        label2.enable(false);
        label3.enable(false);
        scrollbar1.enable(false);
        label6.enable(true);

    }//GEN-LAST:event_button1ActionPerformed

    private void button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button2ActionPerformed
        // TODO add your handling code here:
        valorPintar=2;
        label1.enable(false);
        label2.enable(true);
        label3.enable(false);
        scrollbar1.enable(true);
        label6.enable(false);
    }//GEN-LAST:event_button2ActionPerformed

    private void button3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button3ActionPerformed
        // TODO add your handling code here:
        valorPintar=3;
        label1.enable(false);
        label2.enable(false);
        label3.enable(true);
        scrollbar1.enable(true);
        label6.enable(false);
    }//GEN-LAST:event_button3ActionPerformed

    private void button4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button4ActionPerformed
        // TODO add your handling code here:
        valorColor=1;
        

    }//GEN-LAST:event_button4ActionPerformed

    private void button5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button5ActionPerformed
        // TODO add your handling code here:
        valorColor=2;
    }//GEN-LAST:event_button5ActionPerformed

    private void menuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem3ActionPerformed
        // TODO add your handling code here:
     
    }//GEN-LAST:event_menuItem3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
     /*   java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new editorGrafico().setVisible(true);
            }
        });
*/
        editorGrafico miapp = new editorGrafico();
        miapp.reshape(1000, 1000, 1000, 1000);
        miapp.show();

    }

    public void paint(java.awt.Graphics pContexto) {
        nuestrosObjetos.pintaTodo(pContexto);
    }



    

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Menu File;
    private java.awt.Button button1;
    private java.awt.Button button2;
    private java.awt.Button button3;
    private java.awt.Button button4;
    private java.awt.Button button5;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Label label3;
    private java.awt.Label label4;
    private java.awt.Label label5;
    private java.awt.Label label6;
    private java.awt.MenuBar menuBar1;
    private java.awt.MenuItem menuItem1;
    private java.awt.MenuItem menuItem2;
    private java.awt.MenuItem menuItem3;
    private java.awt.Scrollbar scrollbar1;
    // End of variables declaration//GEN-END:variables
}
